﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using System.ComponentModel;
using System.Collections.ObjectModel;
using Weather3.DataModel;
using System.Diagnostics;



// The Basic Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234237

namespace Weather3
{
    /// <summary>
    /// A basic page that provides characteristics common to most applications.
    /// </summary>
    public sealed partial class CityPage : Weather3.Common.LayoutAwarePage // ,INotifyPropertyChanged
    {
        
        public CityPage()
        {
            this.InitializeComponent();
            var viewModel = new CityViewModel();
            this.DataContext = viewModel;
        }

        

        /// <summary>
        /// Invoked when this page is about to be displayed in a Frame.
        /// </summary>
        /// <param name="e">Event data that describes how this page was reached.  The Parameter
        /// property is typically used to configure the page.</param>
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            var collectionGroups = groupedItemsViewSource.View.CollectionGroups;
            
           // ((ListViewBase)this.Zoom.ZoomedOutView).IsItemClickEnabled = false;
            ((ListViewBase)this.Zoom.ZoomedOutView).ItemsSource = collectionGroups;
            //itemGridView.ItemsSource = collectionGroups;
        }

       
        private void itemGridView_ItemClick_1(object sender, ItemClickEventArgs e)
        {
            City city = e.ClickedItem as City;

            Debug.WriteLine(city.Title);

            (Application.Current as App).City = city.Title;
            this.Frame.Navigate(typeof(GroupDetailPage));
        }

        private void itemGridView_SelectionChanged_1(object sender, SelectionChangedEventArgs e)
        {
            //Object obj = itemGridView.SelectedItem;
            //if (obj!=null)
            //{
            //    City city = (City)obj;

            //    Debug.WriteLine(city.Title);

            //    (Application.Current as App).City = city.Title;
            //    this.Frame.Navigate(typeof(GroupDetailPage));
            //}
            
            
        }

        private void itemGridView_Tapped(object sender, TappedRoutedEventArgs e)
        {
            
            Object obj = itemGridView.SelectedItem;
            if (obj != null)
            {
                City city = (City)obj;

                Debug.WriteLine(city.Title);

                (Application.Current as App).City = city.Title;
                this.Frame.Navigate(typeof(GroupDetailPage));
            }
        }
    }
}
